/* 
Taken from http://clmathlibraries.github.io/clRNG/htmldocs/index.html.
*/

#include <clRNG/mrg31k3p.h>

int main(int argc, char *argv[]) {
	/* We create an array of two streams named streams and a single 
	stream named single. */
    clrngMrg31k3pStream* streams = clrngMrg31k3pCreateStreams(NULL, 2, NULL, NULL);
    clrngMrg31k3pStream* single = clrngMrg31k3pCreateStreams(NULL, 1, NULL, NULL);

    /* Then we repeat the following 100 times: we generate 
    a uniform random number in (0,1) and an integer in {1,…,6}, and 
    compute the indicator that the product is less than 2.*/
    int count = 0;
    for (int i = 0; i < 100; i++) {
        double u = clrngMrg31k3pRandomU01(&streams[i % 2]);
        int    x = clrngMrg31k3pRandomInteger(single, 1, 6);
        if (x * u < 2) count++;

        printf("%f ", u);
    }

    /* The uniform random numbers over (0,1) are generated by 
    alternating the two streams from the array. We then print the 
    average of those indicators. */
    printf("\n");
    printf("Average of indicators = %f\n", (double)count / 100.0);

	return(0);	
}